<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Gmap
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>
<?php 
$this->headTitle('My Gmaps');
?>
<script type="text/javascript">
  var categoryAction =function(category){
    $('category').value = category;
    $('filter_form').submit();
  }
  var tagAction =function(tag){
    $('tag').value = tag;
    $('filter_form').submit();
  }

</script>

<div class="headline">
  <h2>
    <?php echo $this->translate('Gmaps');?>
  </h2>
  <div class="tabs">
    <?php
      // Render the menu
      echo $this->navigation()
        ->menu()
        ->setContainer($this->navigation)
        ->render();
    ?>
  </div>
</div>

<div class='layout_right'>
  <?php echo $this->form->render($this) ?>
  <?php if( $this->can_create): ?>
  <div class="quicklinks">
    <ul>
      <li>
        <a href='<?php echo $this->url(array(), 'gmap_create', true) ?>' class='buttonlink icon_gmap_new'><?php echo $this->translate('Post New Gmap');?></a>
      </li>
    </ul>
  </div>
  <?php endif; ?>
</div>

<div class='layout_middle'>
  <?php if ($this->current_count >= $this->quota  && $this->quota > 0):?>
    <div class="tip">
      <span>
        <?php echo $this->translate('You have already created the maximum number of gmaps allowed. If you would like to create a new gmap, please delete an old one first.');?>
      </span>
    </div>
  <?php endif; ?>
  <?php if ($this->current_count && !$this->has_gmap_home): ?>
    <div class="tip">
      <span>
        <?php echo $this->translate('You do not have a default home location yet. Consider adding or making a location as default so that others can search for you on %s page.',
          $this->htmlLink(array('route'=>'gmap_general','action'=>'members'), $this->translate('Member Locations'))
        );?>
      </span>
    </div>  
  <?php endif; ?>
  
  <?php if( $this->tag || $this->search || $this->location):?>
    <div class='gmaps_result_filter_details'>
      <?php echo $this->translate('Showing gmaps posted'); ?>
      <?php if ($this->tag): ?>
        <?php echo $this->translate('using tag #%s', $this->htmlLink(
          $this->url(array('tag'=>$this->tag), 'gmap_manage', true),
          $this->tagObject ? $this->tagObject->text : $this->tag
        ));?>
      <?php endif; ?>
      <?php if ($this->search): ?>
        <?php echo $this->translate('with keyword %s', $this->htmlLink(
          $this->url(array('search'=>$this->search), 'gmap_manage', true),
          $this->search
        ));?>
      <?php endif; ?>   
      <?php if ($this->location): ?>
        <?php echo $this->translate('around location %s', $this->htmlLink(
          $this->url(array('location'=>$this->location), 'gmap_manage', true),
          $this->location
        ));?>
      <?php endif; ?>  
      <a href="<?php echo $this->url(array(), 'gmap_manage', true) ?>">(x)</a>
    </div>
  <?php endif; ?>
  
  <?php if( $this->paginator->getTotalItemCount() > 0 ): ?>
      <h3 class="sep">
        <span>
          <?php if ($this->categoryObject): ?>
            <?php echo $this->translate($this->categoryObject->category_name); ?>
            <?php $this->headTitle($this->categoryObject->category_name); ?>
          <?php else: ?>  
            <?php echo $this->translate('All Categories'); ?>
          <?php endif; ?>
        </span>
      </h3> 
      
    <div class="gmap_map_container_wrapper">
      <?php echo $this->gmapMarkers($this->google_map, $this->paginator, array('width'=>'740px','height'=>'500px')); ?>
    </div>  
    <div class="gmaps_results">
      <h4 class="sep"><span><?php echo $this->translate(array('%s location found','%s locations found', $this->paginator->getTotalItemCount()), $this->paginator->getTotalItemCount()); ?></span></h4>
  
	    <ul class="gmaps_manage">
	      <?php foreach( $this->paginator as $item ): ?>
	        <li>
	          <div class='gmaps_manage_photo'>
	            <?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'thumb.normal')) ?>
	          </div>
	          <div class='gmaps_manage_options'>
	            <a href='<?php echo $this->url(array('gmap_id' => $item->gmap_id), 'gmap_edit', true) ?>' class='buttonlink icon_gmap_edit'><?php echo $this->translate('Edit Gmap');?></a>
	            <a href='<?php echo $this->url(array('gmap_id' => $item->gmap_id), 'gmap_edit_coordinate', true) ?>' class='buttonlink icon_gmap_coordinate'><?php echo $this->translate('Edit Coordinate');?></a>
	
	            <?php if( $this->allowed_upload ): ?>
	              <?php echo $this->htmlLink(array(
	                  'route' => 'gmap_extended',
	                  'controller' => 'photo',
	                  'action' => 'upload',
	                  'subject' => $item->getGuid(),
	                ), $this->translate('Add Photos'), array(
	                  'class' => 'buttonlink icon_gmap_photo_new'
	              )) ?>
	            <?php endif; ?>
	            <a href='<?php echo $this->url(array('gmap_id' => $item->gmap_id), 'gmap_delete', true) ?>' class='buttonlink icon_gmap_delete'><?php echo $this->translate('Delete Gmap');?></a>
	          </div>
	          <div class='gmaps_manage_info'>
	            <h3>
	                <?php if( $item->home ): ?>
	                  <img src='application/modules/Gmap/externals/images/home.png' class='gmap_title_icon_home' />
	                <?php endif;?>
	                <?php echo $this->htmlLink($item->getHref(), $item->getTitle()) ?>
		              <?php if( $item->featured ): ?>
		                <img src='application/modules/Gmap/externals/images/featured.png' class='gmap_title_icon_featured' />
		              <?php endif;?>
		              <?php if( $item->sponsored ): ?>
		                <img src='application/modules/Gmap/externals/images/sponsored.png' class='gmap_title_icon_sponsored' />
		              <?php endif;?>
	            </h3>
	            <div class='gmap_stats'>
	              <?php echo $this->timestamp(strtotime($item->creation_date)) ?>
	              - <?php echo $this->translate(array("%s view", "%s views", $item->view_count), $item->view_count); ?>
	              - <?php echo $this->translate(array("%s comment", "%s comments", $item->comment_count), $item->comment_count); ?>
	              - <?php echo $this->translate('Coordinate: %1$s, %2$s', array($item->lat, $item->lng))?>
	            </div>
	            <div class='gmap_address'>
	              <?php echo $this->gmapAddressLink($this->google_map, $item)?>
	            </div>
	            <div class='gmap_description'>
	              <?php echo $item->getExcerpt(150) ?>
	            </div>
	          </div>
	        </li>
	      <?php endforeach; ?>
	    </ul>
    </div>
  <?php elseif($this->category || $this->tag || $this->search || $this->location): ?>
    <div class="tip">
      <span>
        <?php echo $this->translate('You do not have any gmap that match your search criteria.');?>
      </span>
    </div>
  <?php else:?>
    <div class="tip">
      <span>
        <?php echo $this->translate('You do not have any gmaps.');?>
        <?php if ($this->can_create): ?>
          <?php echo $this->translate('Get started by <a href=\'%1$s\'>posting</a> a new gmap.', $this->url(array(), 'gmap_create'));?>
        <?php endif; ?>
      </span>
    </div>
  <?php endif; ?>

    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>    
</div>
